package com.ymatou.iapi.productmanager.testcase;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.List;

import org.json.JSONObject;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.productmanager.parameter.product.AddSellerProductRequest;
import com.ymatou.iapi.productmanager.parameter.product.CatalogSaveModel;
import com.ymatou.iapi.productmanager.parameter.product.ModifySellerProductRequest;
import com.ymatou.iapi.productmanager.parameter.product.ProductDescSaveModel;
import com.ymatou.iapi.productmanager.parameter.product.ProductPropertySaveModel;
import com.ymatou.iapi.productmanager.parameter.product.ProductSaveModel;
import com.ymatou.iapi.productmanager.parameter.product.ProductVideoSaveModel;
import com.ymatou.iapi.productmanager.service.AddSellerProductCall;
import com.ymatou.iapi.productmanager.service.ModifySellerProductCall;
import com.ymatou.iapi.productmanager.service.SaveCatalogPackageListCall;
import com.ymatou.iapi.selleractivity.service.ApplyActivityCall;
import com.ymatou.iapi.sellerproduct.parameter.ProdTplBean;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.tag.P1;
import com.ymttest.business.service.ActivityCallService;
import com.ymttest.business.service.AddProductCallService;
import com.ymttest.business.service.ModifyProductCallService;
import com.ymttest.business.service.SellerProductCallService;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.MapUtil;
import com.ymttest.utils.YMTDateUtil;

public class Ts_ModifySellerProduct {
	private static String sellerName = EnvSetup.getData("productsellername");
	
	private static int sellerId = Integer.parseInt(EnvSetup.getData("productsellerid"));
	
	private static ModifySellerProductCall modifySellerProductCall = new ModifySellerProductCall();
	
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("修改商品");
	}
	
	@Before
	public void caseUp() {
	}
	
	@AfterClass
	public static void tearDown() {
		Logger.generateResult(modifySellerProductCall.getOpurl());
	}
	
	@After
	public void caseDown() {
		Logger.end(); 
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ModifySellerProduct_001() throws Exception {
		Logger.start(true,"修改product下属性");
		try{
			AddSellerProductRequest addProdReq = AddProductCallService.getAddSellerProductRequestFromFile("多规格", 
					MapUtil.hashMap("sellerId",sellerId,"sellerName",sellerName));
			
			ModifySellerProductRequest modifyBean = ModifyProductCallService.getModifySellerProductRequestFromAddProductBean(addProdReq);
			
			ProductSaveModel productSaveModel = modifyBean.getProduct();
			//品牌
			productSaveModel.setBrandId(10145);
			productSaveModel.setBrandName("");
			
			//商品名称
			productSaveModel.setProductName("修改测试001");
			
			//修改品类
			productSaveModel.setThirdCategoryId(1460);
			productSaveModel.setSecondCategoryId(1420);
			
			//修改图片信息
			String pic1 = "http:://pic1.ymatou.com/G01//M00/3A/B5/modify-Uj1GHqM097.png";
			String pic2 = "http:://pic1.ymatou.com/G01//M00/322/B5/modify-Uj1GHqM097.png";
			productSaveModel.setProductPicList(Arrays.asList(pic1,pic2));
			
			//修改catalogstatus
			productSaveModel.setCatalogStatus(4);
			productSaveModel.setBondedArea(1);
			
			//noticeRisk
			productSaveModel.setNoticeRisk(true);
			
			//autorefresh
			productSaveModel.setAutoRefresh(true);
			
			//productcode
			productSaveModel.setProductCode("312312325y");
			
			//no reason return
			productSaveModel.setNoReasonReturn(true);
			
			//on sale type
			productSaveModel.setOnSaleType(0);
			
			//Tariff  Type
			productSaveModel.setTariffType(0);
			
			
			JSONObject ret = modifySellerProductCall.callAndGetReturnData(modifyBean);
			Logger.verifyEquals(200, ret.getInt("Code"), "返回码校验");
			
			
			productSaveModel.setValidStart(new SimpleDateFormat(YMTDateUtil.YMDHMS).format(YMTDateUtil.getDate()));
			productSaveModel.setValidEnd(new SimpleDateFormat(YMTDateUtil.YMDHMS).format(YMTDateUtil.getBeforeOrNextDate(7)));
			ModifyProductCallService.checkAddProduct(modifyBean);

		
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ModifySellerProduct_002() throws Exception {
		Logger.start(true,"修改product下属性 定期上架");
		try{
			AddSellerProductRequest addProdReq = AddProductCallService.getAddSellerProductRequestFromFile("多规格", 
					MapUtil.hashMap("sellerId",sellerId,"sellerName",sellerName));
			
			ModifySellerProductRequest modifyBean = ModifyProductCallService.getModifySellerProductRequestFromAddProductBean(addProdReq);
			
			ProductSaveModel productSaveModel = modifyBean.getProduct();
			
			//onSaleType 定期上架
			productSaveModel.setOnSaleType(1);
			productSaveModel.setValidStart(new SimpleDateFormat(YMTDateUtil.YMDHMS).format(YMTDateUtil.getDate()));
			productSaveModel.setValidEnd(new SimpleDateFormat(YMTDateUtil.YMDHMS).format(YMTDateUtil.getBeforeOrNextDate(7)));
			
			modifyAndCheck(modifyBean);

		
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ModifySellerProduct_003() throws Exception {
		Logger.start(true,"修改product下属性 修改视频");
		try{
			AddSellerProductRequest addProdReq = AddProductCallService.getAddSellerProductRequestFromFile("多规格", 
					MapUtil.hashMap("sellerId",sellerId,"sellerName",sellerName));
			
			ModifySellerProductRequest modifyBean = ModifyProductCallService.getModifySellerProductRequestFromAddProductBean(addProdReq);
			
			ProductSaveModel productSaveModel = modifyBean.getProduct();
			
			//新增视频
			ProductVideoSaveModel productVideo = new ProductVideoSaveModel();
			productVideo.setVideoUrl("http://v2.ymatou.com/uploads/20180103/6a44924f0b4968e88321061a3704b4cf.mp4");
			productVideo.setPic("http://pic1.ymatou.com/G01/shangou/modif/3B/22/rBBlD1pMiOCAWitxAADUmGEFNI0402_1_1_n_w_o.jpg");
			productVideo.setLength(11573);
			productVideo.setWidth(400);
			productVideo.setHeight(30);
			productVideo.setSize(3070568);
			productSaveModel.setVideoModel(productVideo);
			modifyAndCheck(modifyBean);

			
			//修改视频
			ProductVideoSaveModel productVideo2 = new ProductVideoSaveModel();
			productVideo2.setVideoUrl("http://v2.ymatou.com/uploads/20180122/6a44924f0b4968e88321231061a3704b4cf.mp4");
			productVideo2.setPic("http://pic1.ymatou.com/G01/shangou/add/3B/22/rBBlD1pMi123OCAWitxAADUmGEFNI0402_1_1_n_w_o.jpg");
			productVideo2.setLength(11173);
			productVideo2.setWidth(440);
			productVideo2.setHeight(410);
			productVideo2.setSize(307218);
			productSaveModel.setVideoModel(productVideo2);
			modifyAndCheck(modifyBean);
		
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ModifySellerProduct_004() throws Exception {
		Logger.start(true,"修改product descModel下属性 修改文描和图片");
		try{
			AddSellerProductRequest addProdReq = AddProductCallService.getAddSellerProductRequestFromFile("多规格", 
					MapUtil.hashMap("sellerId",sellerId,"sellerName",sellerName));
			
			ModifySellerProductRequest modifyBean = ModifyProductCallService.getModifySellerProductRequestFromAddProductBean(addProdReq);
			
			ProductDescSaveModel descModel = modifyBean.getProduct().getDescModel();
			String pic1 = "http:://pic1.ymatou.com/G01//M00/3A/B5/modifydes-Uj1GHqM004.png";
			String pic2 = "http:://pic1.ymatou.com/G01//M00/322/B5/modifydes-Uj1GHqM004.png";
			String pic3 = "http:://pic1.ymatou.com/G01//M00/322/B5/modifydes-Uj1G2134.png";
			descModel.setDescPicList(Arrays.asList(pic1,pic2,pic3));
			descModel.setDescription("修改文描测试");
			
			JSONObject ret = modifySellerProductCall.callAndGetReturnData(modifyBean);
			Logger.verifyEquals(200, ret.getInt("Code"), "返回码校验");
			
			ModifyProductCallService.checkAddProduct(modifyBean);

		
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ModifySellerProduct_005() throws Exception {
		Logger.start(true,"修改product descModel下属性 修改sizeTemplateId,buyerNoticeId,sellerServiceId");
		try{
			AddSellerProductRequest addProdReq = AddProductCallService.getAddSellerProductRequestFromFile("多规格", 
					MapUtil.hashMap("sellerId",sellerId,"sellerName",sellerName));
			
			ModifySellerProductRequest modifyBean = ModifyProductCallService.getModifySellerProductRequestFromAddProductBean(addProdReq);
			ProductDescSaveModel descModel = modifyBean.getProduct().getDescModel();
			
			//新增templateID
			SellerProductCallService.deleteTemplate(sellerId);
			//	模版类型（1，尺码模版 2，买家须知 3，买手服务）
			ProdTplBean sizeTemplate = SellerProductCallService.saveTemplate(sellerId, 1);
			ProdTplBean buyerNoticeTemplate = SellerProductCallService.saveTemplate(sellerId, 2);
			ProdTplBean sellerServiceTemplate = SellerProductCallService.saveTemplate(sellerId, 3);
			
			descModel.setSizeTemplateId(sizeTemplate.getTemplateId());
			descModel.setBuyerNoticeId(buyerNoticeTemplate.getTemplateId());
			descModel.setSellerServiceId(sellerServiceTemplate.getTemplateId());
			
			modifyAndCheck(modifyBean);
			
			//修改templateID
			//	模版类型（1，尺码模版 2，买家须知 3，买手服务）
			ProdTplBean sizeTemplate2 = SellerProductCallService.saveTemplate(sellerId, 1);
			ProdTplBean buyerNoticeTemplate2 = SellerProductCallService.saveTemplate(sellerId, 2);
			ProdTplBean sellerServiceTemplate2 = SellerProductCallService.saveTemplate(sellerId, 3);
			
			descModel.setSizeTemplateId(sizeTemplate2.getTemplateId());
			descModel.setBuyerNoticeId(buyerNoticeTemplate2.getTemplateId());
			descModel.setSellerServiceId(sellerServiceTemplate2.getTemplateId());
			
			modifyAndCheck(modifyBean);
			
			
			

		
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ModifySellerProduct_006() throws Exception {
		Logger.start(true,"修改product descModel下属性 修改declaration");
		try{
			AddSellerProductRequest addProdReq = AddProductCallService.getAddSellerProductRequestFromFile("多规格", 
					MapUtil.hashMap("sellerId",sellerId,"sellerName",sellerName));
			
			ModifySellerProductRequest modifyBean = ModifyProductCallService.getModifySellerProductRequestFromAddProductBean(addProdReq);
			ProductDescSaveModel descModel = modifyBean.getProduct().getDescModel();
			
			//新增declaration
			descModel.setDeclarationId(4412);
			modifyAndCheck(modifyBean);
			
			//修改declaration
			descModel.setDeclarationId(4123);
			modifyAndCheck(modifyBean);
			
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ModifySellerProduct_007() throws Exception {
		Logger.start(true,"修改product descModel下属性 修改spuId");
		try{
			AddSellerProductRequest addProdReq = AddProductCallService.getAddSellerProductRequestFromFile("多规格", 
					MapUtil.hashMap("sellerId",sellerId,"sellerName",sellerName));
			
			ModifySellerProductRequest modifyBean = ModifyProductCallService.getModifySellerProductRequestFromAddProductBean(addProdReq);
			
			//新增spu
			modifyBean.getProduct().setSpuId(123);
			modifyAndCheck(modifyBean);
			
			//修改spu
			modifyBean.getProduct().setSpuId(234);
			modifyAndCheck(modifyBean);
			
			
			
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ModifySellerProduct_008() throws Exception {
		Logger.start(true,"修改product descModel下属性 修改商品属性值");
		try{
			AddSellerProductRequest addProdReq = AddProductCallService.getAddSellerProductRequestFromFile("多规格", 
					MapUtil.hashMap("sellerId",sellerId,"sellerName",sellerName));
			
			ModifySellerProductRequest modifyBean = ModifyProductCallService.getModifySellerProductRequestFromAddProductBean(addProdReq);
			List<ProductPropertySaveModel> prodPropertyList = modifyBean.getProduct().getPropertyList();
			
			
			//修改原有属性
			prodPropertyList.get(0).setPropertyValues(Arrays.asList("中国"));
			modifyAndCheck(modifyBean);
			
			//新增属性
			
			ProductPropertySaveModel newPropertyModel = new ProductPropertySaveModel();
			newPropertyModel.setPropertyId(71);
			newPropertyModel.setPropertyValues(Arrays.asList("11","12"));
			
			
			ProductPropertySaveModel newPropertyModel2 = new ProductPropertySaveModel();
			newPropertyModel2.setPropertyId(26);
			newPropertyModel2.setPropertyValues(Arrays.asList("小样"));
			
			prodPropertyList.add(newPropertyModel);
			prodPropertyList.add(newPropertyModel2);
			
			modifyAndCheck(modifyBean);
			
			//删除部分属性
			prodPropertyList.remove(1);
			modifyAndCheck(modifyBean);
			
		
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	
	
	
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ModifySellerProduct_009() throws Exception {
		Logger.start(true,"修改product 规格节点下普通属性");
		try{
			AddSellerProductRequest addProdReq = AddProductCallService.getAddSellerProductRequestFromFile("多规格", 
					MapUtil.hashMap("sellerId",sellerId,"sellerName",sellerName));
			
			ModifySellerProductRequest modifyBean = ModifyProductCallService.getModifySellerProductRequestFromAddProductBean(addProdReq);
			
			List<CatalogSaveModel> catalogList = modifyBean.getProduct().getCatalogList();
			CatalogSaveModel catalogMode1 = catalogList.get(0);
			CatalogSaveModel catalogMode2 = catalogList.get(1);
			
			//price
			catalogMode1.setPrice(31231.01);
			catalogMode2.setPrice(31244.02);
			
			//vip price
			catalogMode1.setVipPrice(1233.12);
			catalogMode2.setVipPrice(1232.12);
			
			//new price
			catalogMode1.setNewPrice(312.22);
			catalogMode2.setNewPrice(154.3);
			
			//stock
			catalogMode1.setStock(3000);
			catalogMode2.setStock(3022);
			
			//sku
			catalogMode1.setSku("modify123");
			catalogMode2.setSku("modify321");
			
			//productcode
			catalogMode1.setProductCode("123modifycode");
			catalogMode2.setProductCode("321modifycode");
			
			//weight
			catalogMode1.setWeight(12.1);
			catalogMode2.setWeight(21.1);
			
			
			modifyAndCheck(modifyBean);
			
			
			
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	
	
	
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ModifySellerProduct_010() throws Exception {
		Logger.start(true,"修改product 规格节点下多物流和预售属性");
		try{
			AddSellerProductRequest addProdReq = AddProductCallService.getAddSellerProductRequestFromFile("多规格", 
					MapUtil.hashMap("sellerId",sellerId,"sellerName",sellerName));
			
			ModifySellerProductRequest modifyBean = ModifyProductCallService.getModifySellerProductRequestFromAddProductBean(addProdReq);
			
			List<CatalogSaveModel> catalogList = modifyBean.getProduct().getCatalogList();
			CatalogSaveModel catalogMode1 = catalogList.get(0);
			CatalogSaveModel catalogMode2 = catalogList.get(1);
			
			//多物流支持
			catalogMode2.setMultiLogistics(1);
			
			//修改预售
			catalogMode1.setPreSale(true);
			
			
			modifyAndCheck(modifyBean);
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	
	

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ModifySellerProduct_011() throws Exception {
		Logger.start(true,"修改product 规格节点下套装属性");
		try{
			SaveCatalogPackageListCall saveCatalogPackageListCall = new SaveCatalogPackageListCall();
			int packageId1 = saveCatalogPackageListCall.callAndGetReturnData(MapUtil.hashMap("ProductPackageList[0]->SubCatalogName","测试组合001测试组合001"))
									.getJSONObject("Data").getJSONArray("SubCatalogIdList").getInt(0);
			
			int packageId2 = saveCatalogPackageListCall.callAndGetReturnData(MapUtil.hashMap("ProductPackageList[0]->SubCatalogName","测试组合002测试组合001"))
					.getJSONObject("Data").getJSONArray("SubCatalogIdList").getInt(0);
			
			AddSellerProductRequest addProdReq = AddProductCallService.getAddSellerProductRequestFromFile("多规格", 
					MapUtil.hashMap("sellerId",sellerId,"sellerName",sellerName));
			
			ModifySellerProductRequest modifyBean = ModifyProductCallService.getModifySellerProductRequestFromAddProductBean(addProdReq);
			
			List<CatalogSaveModel> catalogList = modifyBean.getProduct().getCatalogList();
			CatalogSaveModel catalogMode1 = catalogList.get(0);
			CatalogSaveModel catalogMode2 = catalogList.get(1);
			
			
			//新增套装
			catalogMode1.setPackage(true);
			catalogMode1.setSubCatalogIdList(Arrays.asList(packageId1));
			
			catalogMode2.setPackage(true);
			catalogMode2.setSubCatalogIdList(Arrays.asList(packageId2));
			modifyAndCheck(modifyBean);
			
			// 删除套装
			catalogMode1.setPackage(false);
			catalogMode1.setSubCatalogIdList(null);
			modifyAndCheck(modifyBean);
			
			//修改
			int packageId3 = saveCatalogPackageListCall.callAndGetReturnData(MapUtil.hashMap("ProductPackageList[0]->SubCatalogName","测试组合003测试组合001"))
					.getJSONObject("Data").getJSONArray("SubCatalogIdList").getInt(0);
			catalogMode2.setSubCatalogIdList(Arrays.asList(packageId2,packageId3));
			modifyAndCheck(modifyBean);
			
			
			//删除一个
			catalogMode2.setSubCatalogIdList(Arrays.asList(packageId3));
			modifyAndCheck(modifyBean);
			
			
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ModifySellerProduct_012() throws Exception {
		Logger.start(true,"修改product 规格节点下属性图");
		try{
			AddSellerProductRequest addProdReq = AddProductCallService.getAddSellerProductRequestFromFile("多规格", 
					MapUtil.hashMap("sellerId",sellerId,"sellerName",sellerName));
			
			ModifySellerProductRequest modifyBean = ModifyProductCallService.getModifySellerProductRequestFromAddProductBean(addProdReq);
			
			List<CatalogSaveModel> catalogList = modifyBean.getProduct().getCatalogList();
			CatalogSaveModel catalogMode1 = catalogList.get(0);
			
			//修改属性图
			catalogMode1.getPropertyList().get(0).setPropertyUrl("http://pic1.ymatou.com/G01//modify1/3A/B5/rBBlD1n4FoqAEeSFAAdYEcXNxCc313.png");
			catalogMode1.getPropertyList().get(1).setPropertyUrl("http://pic1.ymatou.com/G01//modify2/23A/B5/rBBlD1n4FoqAEeSFAAdYEcXNxCc313.png");
			modifyAndCheck(modifyBean);
			
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ModifySellerProduct_013() throws Exception {
		Logger.start(true,"修改product 规格节 新增 删除规格");
		try{
			AddSellerProductRequest addProdReq = AddProductCallService.getAddSellerProductRequestFromFile("多规格", 
					MapUtil.hashMap("sellerId",sellerId,"sellerName",sellerName));
			
			ModifySellerProductRequest modifyBean = ModifyProductCallService.getModifySellerProductRequestFromAddProductBean(addProdReq);
			
			List<CatalogSaveModel> catalogList = modifyBean.getProduct().getCatalogList();
			CatalogSaveModel catalogMode1 = catalogList.get(0);
			CatalogSaveModel catalogMode2 = catalogList.get(1);
			
			//规格1 只变价格
			catalogMode1.setPrice(1231.23);
			
			//规格2 删除
			catalogMode2.setOperateType(3);
			
			//新增规格3 
			AddSellerProductRequest addProdReq2 = AddProductCallService.getAddSellerProductRequestFromFile("多规格", 
					MapUtil.hashMap("sellerId",sellerId,"sellerName",sellerName));
			CatalogSaveModel catalogMode3 = addProdReq2.getProduct().getCatalogList().get(0);
			catalogMode3.setPrice(32344.32);
			catalogMode3.getPropertyList().get(0).setPropertyValue("绿色");
			catalogMode3.getPropertyList().get(1).setPropertyValue("L");
			catalogMode3.setOperateType(1);
			catalogList.add(catalogMode3);
			
			
			modifyAndCheck(modifyBean);
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ModifySellerProduct_013_001() throws Exception {
		Logger.start(true,"修改product 规格节 新增 删除规格 app兼容,删除时候不传该规格");
		try{
			AddSellerProductRequest addProdReq = AddProductCallService.getAddSellerProductRequestFromFile("多规格", 
					MapUtil.hashMap("sellerId",sellerId,"sellerName",sellerName));
			
			ModifySellerProductRequest modifyBean = ModifyProductCallService.getModifySellerProductRequestFromAddProductBean(addProdReq);
			
			List<CatalogSaveModel> catalogList = modifyBean.getProduct().getCatalogList();
			CatalogSaveModel catalogMode1 = catalogList.get(0);
			CatalogSaveModel catalogMode2 = catalogList.get(1);
			
			//规格1 只变价格
			catalogMode1.setPrice(1231.23);
			
			//规格2 删除
			catalogList.remove(catalogMode2);
			
			//新增规格3 
			AddSellerProductRequest addProdReq2 = AddProductCallService.getAddSellerProductRequestFromFile("多规格", 
					MapUtil.hashMap("sellerId",sellerId,"sellerName",sellerName));
			CatalogSaveModel catalogMode3 = addProdReq2.getProduct().getCatalogList().get(0);
			catalogMode3.setPrice(32344.32);
			catalogMode3.getPropertyList().get(0).setPropertyValue("绿色");
			catalogMode3.getPropertyList().get(1).setPropertyValue("L");
			catalogMode3.setOperateType(1);
			catalogList.add(catalogMode3);
			
			
			modifyAndCheck(modifyBean);
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	
	
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ModifySellerProduct_013_002() throws Exception {
		Logger.start(true,"修改product 规格节 新增 删除规格 app兼容,删除时候不传该规格  老规格全删除");
		try{
			AddSellerProductRequest addProdReq = AddProductCallService.getAddSellerProductRequestFromFile("多规格", 
					MapUtil.hashMap("sellerId",sellerId,"sellerName",sellerName));
			
			ModifySellerProductRequest modifyBean = ModifyProductCallService.getModifySellerProductRequestFromAddProductBean(addProdReq);
			
			List<CatalogSaveModel> catalogList = modifyBean.getProduct().getCatalogList();
			CatalogSaveModel catalogMode1 = catalogList.get(0);
			CatalogSaveModel catalogMode2 = catalogList.get(1);
			
			
			//规格1,2 删除
			catalogList.remove(catalogMode1);
			catalogList.remove(catalogMode2);
			
			//新增规格3 
			AddSellerProductRequest addProdReq2 = AddProductCallService.getAddSellerProductRequestFromFile("多规格", 
					MapUtil.hashMap("sellerId",sellerId,"sellerName",sellerName));
			CatalogSaveModel catalogMode3 = addProdReq2.getProduct().getCatalogList().get(0);
			catalogMode3.setPrice(32344.32);
			catalogMode3.getPropertyList().get(0).setPropertyValue("绿色");
			catalogMode3.getPropertyList().get(1).setPropertyValue("L");
			catalogMode3.setOperateType(1);
			catalogList.add(catalogMode3);
			
			
			modifyAndCheck(modifyBean);
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ModifySellerProduct_013_003() throws Exception {
		Logger.start(true,"修改product app 单规格修改 不传规格id");
		try{
			AddSellerProductRequest addProdReq = AddProductCallService.getAddSellerProductRequestFromFile("单规格", 
					MapUtil.hashMap("sellerId",sellerId,"sellerName",sellerName));
			
			ModifySellerProductRequest modifyBean = ModifyProductCallService.getModifySellerProductRequestFromAddProductBean(addProdReq);
			
			
			//规格1 只变价格
			String catalogId = modifyBean.getProduct().getCatalogList().get(0).getCatalogId();
			modifyBean.getProduct().getCatalogList().get(0).setPrice(12313.12);
			modifyBean.getProduct().getCatalogList().get(0).setCatalogId(null);
			
			JSONObject ret = modifySellerProductCall.callAndGetReturnData(modifyBean);
			Logger.verifyEquals(200, ret.getInt("Code"), "返回码校验");
			modifyBean.getProduct().getCatalogList().get(0).setCatalogId(catalogId);
			ModifyProductCallService.checkAddProduct(modifyBean);
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ModifySellerProduct_013_004() throws Exception {
		Logger.start(true,"修改product app 多规格修改单规格修改 不传规格id");
		try{
			AddSellerProductRequest addProdReq = AddProductCallService.getAddSellerProductRequestFromFile("多规格", 
					MapUtil.hashMap("sellerId",sellerId,"sellerName",sellerName));
			
			ModifySellerProductRequest modifyBean = ModifyProductCallService.getModifySellerProductRequestFromAddProductBean(addProdReq);
			
			modifyBean.getProduct().getCatalogList().remove(1);
			//规格1 只变价格
			modifyBean.getProduct().getCatalogList().get(0).setPrice(12313.12);
			modifyBean.getProduct().getCatalogList().get(0).setCatalogId(null);
			
			JSONObject ret = modifySellerProductCall.callAndGetReturnData(modifyBean);
			Logger.verifyEquals(201, ret.getInt("Code"), "返回码校验");
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ModifySellerProduct_014() throws Exception {
		Logger.start(true,"修改product 多规格变单规格");
		try{
			AddSellerProductRequest addProdReq = AddProductCallService.getAddSellerProductRequestFromFile("多规格", 
					MapUtil.hashMap("sellerId",sellerId,"sellerName",sellerName));
			
			ModifySellerProductRequest modifyBean = ModifyProductCallService.getModifySellerProductRequestFromAddProductBean(addProdReq);
			
			List<CatalogSaveModel> catalogList = modifyBean.getProduct().getCatalogList();
			CatalogSaveModel catalogMode1 = catalogList.get(0);
			CatalogSaveModel catalogMode2 = catalogList.get(1);
			
			//规格1,2 删除
			catalogMode1.setOperateType(3);
			catalogMode2.setOperateType(3);
			
			//新增单规格3 
			AddSellerProductRequest addProdReq2 = AddProductCallService.getAddSellerProductRequestFromFile("单规格", 
					MapUtil.hashMap("sellerId",sellerId,"sellerName",sellerName));
			CatalogSaveModel catalogMode3 = addProdReq2.getProduct().getCatalogList().get(0);
			catalogMode3.setPrice(3144.32);
			catalogMode3.setOperateType(1);
			catalogList.add(catalogMode3);
			
			
			modifyAndCheck(modifyBean);
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ModifySellerProduct_015() throws Exception {
		Logger.start(true,"修改product 单规格变多规格");
		try{
			AddSellerProductRequest addProdReq = AddProductCallService.getAddSellerProductRequestFromFile("单规格", 
					MapUtil.hashMap("sellerId",sellerId,"sellerName",sellerName));
			
			ModifySellerProductRequest modifyBean = ModifyProductCallService.getModifySellerProductRequestFromAddProductBean(addProdReq);
			
			List<CatalogSaveModel> catalogList = modifyBean.getProduct().getCatalogList();
			
			//规格删除
			catalogList.get(0).setOperateType(3);
			
			AddSellerProductRequest addProdReq2 = AddProductCallService.getAddSellerProductRequestFromFile("多规格", 
					MapUtil.hashMap("sellerId",sellerId,"sellerName",sellerName));
			CatalogSaveModel catalogMode2 = addProdReq2.getProduct().getCatalogList().get(0);
			catalogMode2.setPrice(31144.02);
			catalogMode2.setOperateType(1);
			catalogList.add(catalogMode2);
			
			CatalogSaveModel catalogMode3 = addProdReq2.getProduct().getCatalogList().get(1);
			catalogMode3.setPrice(33344.32);
			catalogMode3.setOperateType(1);
			
			catalogList.add(catalogMode3);
			
			modifyAndCheck(modifyBean);
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ModifySellerProduct_016() throws Exception {
		Logger.start(true,"修改product 多规格启用，未启用");
		try{
			AddSellerProductRequest addProdReq = AddProductCallService.getAddSellerProductRequestFromFile("多规格", 
					MapUtil.hashMap("sellerId",sellerId,"sellerName",sellerName));
			
			ModifySellerProductRequest modifyBean = ModifyProductCallService.getModifySellerProductRequestFromAddProductBean(addProdReq);
			
			
			//未启用
			modifyBean.getProduct().getCatalogList().get(0).setAction(-2);
			modifyAndCheck(modifyBean);
			
			
			//启用
			modifyBean.getProduct().getCatalogList().get(0).setAction(0);
			modifyAndCheck(modifyBean);
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ModifySellerProduct_017() throws Exception {
		Logger.start(true,"修改product 多物流方式和差价");
		try{
			AddSellerProductRequest addProdReq = AddProductCallService.getAddSellerProductRequestFromFile("多规格", 
					MapUtil.hashMap("sellerId",sellerId,"sellerName",sellerName));
			
			ModifySellerProductRequest modifyBean = ModifyProductCallService.getModifySellerProductRequestFromAddProductBean(addProdReq);
			
			
			modifyBean.getProduct().setMultiLogistics(3);
			modifyBean.getProduct().setFlightBalance(20d);
			modifyBean.getProduct().getCatalogList().get(0).setMultiLogistics(3);
			
			modifyAndCheck(modifyBean);
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ModifySellerProduct_018() throws Exception {
		Logger.start(true,"正在进行活动商品不能修改");
		try{
			AddSellerProductRequest addProdReq = AddProductCallService.getAddSellerProductRequestFromFile("多规格", 
					MapUtil.hashMap("sellerId",sellerId,"sellerName",sellerName));
			String productId = new AddSellerProductCall().callAndGetReturnData(addProdReq).getJSONObject("Data").getString("ProductId");
			
			//参加活动
			AddProductCallService.getProdPriceWithActivity(sellerId,productId,null);
			
			ModifySellerProductRequest modifyBean = ModifyProductCallService.getModifySellerProductRequestFromAddProductBean(productId,addProdReq);
			
			JSONObject ret = modifySellerProductCall.callAndGetReturnData(modifyBean);
			Logger.verifyEquals(201, ret.getInt("Code"), "返回码校验");
			
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ModifySellerProduct_019() throws Exception {
		Logger.start(true,"编辑报名参加活动商品");
		try{
			AddSellerProductRequest addProdReq = AddProductCallService.getAddSellerProductRequestFromFile("多规格", 
					MapUtil.hashMap("sellerId",sellerId,"sellerName",sellerName));
			String productId = new AddSellerProductCall().callAndGetReturnData(addProdReq).getJSONObject("Data").getString("ProductId");
			
			// 报名活动
			int activityId = ActivityCallService.createActivityInProcess(null);
			ApplyActivityCall.applyProductInActivity(sellerId, productId, activityId, MapUtil.hashMap());

			
			ModifySellerProductRequest modifyBean = ModifyProductCallService.getModifySellerProductRequestFromAddProductBean(productId,addProdReq);
			
			
			//手动查日志
			//没变 不发消息
			modifySellerProductCall.callAndGetReturnData(modifyBean);
			
			//规格变 发消息
			modifyBean.getProduct().getCatalogList().get(0).setPrice(12344);
			modifySellerProductCall.callAndGetReturnData(modifyBean);
			
			
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	
	
	
	
	public static void modifyAndCheck(ModifySellerProductRequest modifyBean) throws Exception{
		JSONObject ret = modifySellerProductCall.callAndGetReturnData(modifyBean);
		Logger.verifyEquals(200, ret.getInt("Code"), "返回码校验");
		ModifyProductCallService.checkAddProduct(modifyBean);
	}
}
